package cn.leonis.leetcode;

/**
 * @Author Tobi
 * @Date 2021-12-12 下午1:23
 * 转换为小写
 * leetcode709
 */
public class ToLowerCaseSolution {

    public static void main(String[] args) {
        String s = "HELLO";
        ToLowerCaseSolution solution = new ToLowerCaseSolution();
        String result = solution.toLowerCase(s);
        System.out.println(result);
    }

    /**
     * 解法：自己动手实现
     * @param s
     * @return
     */
    public String toLowerCase(String s) {
        StringBuffer sb = new StringBuffer();
        char[] chars = s.toCharArray();
        for (char c : chars) {
            if (c >= 65 && c <= 90) {
                c |= 32;
            }
            sb.append(c);
        }

        return sb.toString();
    }

    /**
     * 使用系统API
     * @param s
     * @return
     */
    public String toLowerCase2(String s) {
        return s.toLowerCase();
    }
}
